{{Strip}}{{Extend "layout"}}
{{Block "title"}}{{"网站列表"|T}}{{/Block}}
{{Block "breadcrumb"}}
{{Super}}
<li class="active">{{"网站列表"|T}}</li>
{{/Block}}
{{Block "main"}}
<div class="row">
	<div class="col-md-12">
		<div class="block-flat">
			<div class="header">
				<div class="pull-right" style="margin-left:10px">
					<form class="form-horizontal" action="" id="search-form" method="GET">
						<div class="input-group">
							<span class="input-group-addon">{{"分组"|T}}</span>
							<select name="groupId" class="form-control" id="groupId" onchange="$('#search-form').submit()">
								<option value="0"> - {{"不限"|T}} - </option>
								{{$groupId := Stored.groupId}} 
								{{range $k, $v := Stored.groupList}}
								<option value="{{$v.Id}}" {{if eq $groupId $v.Id}} selected{{end}}>{{$v.Name}}</option>
								{{end}}
							</select>
						</div>
					</form>
				</div>
				<a href="__BACKEND__/caddy/vhost_add" class="btn btn-success pull-right">
					<i class="fa fa-plus"></i>
					{{"添加网站"|T}}
				</a>
				<a href="__BACKEND__/caddy/vhost_build" class="pull-right btn btn-warning">
                    <i class="fa fa-refresh"></i>
                    {{"应用配置"|T}}
                </a>
				<h3>{{"网站列表"|T}}</h3>
			</div>
			<div class="content">
				<div class="table-responsive">
				<table class="table no-border hover">
					<thead class="no-border">
						<tr>
							<th style="width:50px"><strong>ID</strong></th>
							<th style="width:150px"><strong>{{"网站名称"|T}}</strong></th>
							<th><strong>{{"地址"|T}}</strong></th>
							<th style="width:100px"><strong>{{"分组"|T}}</strong></th>
							<th style="width:170px"><strong>{{"时间"|T}}</strong></th>
							<th style="width:60px"><strong>{{"状态"|T}}</strong></th>
							<th style="width:145px" class="text-center"><strong>{{"操作"|T}}</strong></th>
						</tr>
					</thead>
					<tbody class="no-border-y">
                        {{- range $k,$v := Stored.listData}}
						<tr>
							<td>{{$v.Id}}</td>
							<td>{{- $vhostName := $v.Name|Default (T "未设置") -}}
								{{- $domainList := Split $v.Domain " " -}}
								{{- $domian := index $domainList 0 -}}
								{{- if and (not (Contains $domian "$")) (not (Contains $domian "%")) -}}
								{{- if HasPrefix $domian ":" -}}
								<a href="http://127.0.0.1{{$domian}}" target="_blank">{{$vhostName}}</a>
								{{- else if HasPrefix $domian "0.0.0.0:" -}}
								<a href="http://127.0.0.1{{TrimLeft $domian "0.0.0.0"}}" target="_blank">{{$vhostName}}</a>
								{{- else if not (Contains $domian "//") -}}
								<a href="http://{{$domian}}" target="_blank">{{$vhostName}}</a>
								{{- else -}}
								<a href="{{Replace $domian "*" "test" -1}}" target="_blank">{{$vhostName}}</a>
								{{- end -}}
								{{- else -}}
								{{$vhostName}}
								{{- end -}}</td>
							<td>
								{{- "监听地址"|T}}: {{$v.Domain}}<br />
								{{- "物理路径"|T}}: {{$v.Root -}}
							</td>
							<td>{{if $v.Group}}{{$v.Group.Name}}{{else}}{{"无"|T}}{{end}}</td>
							<td>
								{{- "创建"|T}}: {{(Date $v.Created).Format "2006-01-02 15:04:05" -}}<br />
								{{- "更新"|T}}: {{if gt $v.Updated 0}}{{(Date $v.Updated).Format "2006-01-02 15:04:05"}}{{end -}}
							</td>
							<td>
								<div class="checkbox checkbox-success no-margin-y">
									<input id="checkbox-{{$k}}" class="styled switch-disabled" type="checkbox" data-id="{{$v.Id}}" data-disabled="{{$v.Disabled}}"{{if eq $v.Disabled "N"}} checked="checked"{{end}} value="N" /><label for="checkbox-{{$k}}">{{"启用"|T}}</label>
								</div>
							</td>
							<td class="text-center">
								<a class="label label-default" href="__BACKEND__/caddy/vhost_add?copyId={{$v.Id}}" title="{{"复制"|T}}" data-toggle="tooltip"><i class="fa fa-copy"></i></a>
								<a class="label label-success" href="__BACKEND__/caddy/vhost_edit?id={{$v.Id}}" title="{{"编辑"|T}}" data-toggle="tooltip"><i class="fa fa-pencil"></i></a>
								<a class="label label-danger" href="__BACKEND__/caddy/vhost_delete?id={{$v.Id}}" onclick="return confirm('{{"真的要删除吗？"|T}}');" title="{{"删除"|T}}" data-toggle="tooltip"><i class="fa fa-times"></i></a>
								{{- if $v.Root}}
								<a class="label label-primary" href="__BACKEND__/caddy/vhost_file?id={{$v.Id}}" title="{{"文件管理"|T}}" data-toggle="tooltip"><i class="fa fa-folder"></i>
								</a>
								{{- end -}}
							</td>
						</tr>
                        {{end -}}
					</tbody>
				</table>		
				</div>
				{{Stored.pagination.Render}}
			</div>
		</div>				
	</div>
</div>
{{/Block}}
{{Block "footer"}}
<script>
$(function(){
	$('input.switch-disabled').on('click',function(r){
		var that=$(this),disabled=that.data('disabled')=='Y'?'N':'Y';
		$.get(BACKEND_URL+'/caddy/vhost_edit',{
			disabled:disabled,
			id:that.data('id')
		},function(r){
			if(r.Code==1){
				that.data('disabled',disabled);
				that.prop('checked',disabled=='N');
			}
			App.message({title:'{{"系统消息"|T}}',text:r.Info,time:5000,sticky:false,class_name:r.Code==1?'success':'error'});
		},'json');
	});
});
</script>
{{/Block}}
{{/Strip}}